package Presentacion;

import ModeloLogicoSistema.AdministradorCliente;
import ModeloLogicoSistema.AdministradorOrden;
import ModeloLogicoSistema.AdministradorServicio;
import ModeloLogicoSistema.Cliente;
import ModeloLogicoSistema.Orden;
import ModeloLogicoSistema.ServicioContratado;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;;
import javax.swing.table.DefaultTableModel;


/**
 *
 * @author Veko
 */
public class ModificacionOrden extends javax.swing.JDialog {
    
    private AdministradorCliente administradorClientes = null;
    private AdministradorOrden administradorOrden = null;
    private Calendar calendario = new GregorianCalendar();
    private Cliente cliente;
    private Orden orden;
    private ArrayList<ServicioContratado> serviciosContratados = new ArrayList<>();
    private SimpleDateFormat formateador = new SimpleDateFormat("dd/MM/yyyy");
    private SimpleDateFormat formateadorFechaHoy = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    private String fechaHoy=null;

    private void cargarTablaPendientes(){
        String primerDia,segundoDia,tercerDia,cuartoDia,quintoDia,sextoDia,
                septimoDia,octavoDia;
        Calendar cal=Calendar.getInstance();
        fechaHoy=formateadorFechaHoy.format(cal.getTime());
        primerDia=formateador.format(cal.getTime());
        cal.add(Calendar.DATE, 1);
        segundoDia= formateador.format(cal.getTime());
        cal.add(Calendar.DATE, 1);
        tercerDia=formateador.format(cal.getTime());
        cal.add(Calendar.DATE, 1);
        cuartoDia=formateador.format(cal.getTime());
        cal.add(Calendar.DATE, 1);
        quintoDia=formateador.format(cal.getTime());
        cal.add(Calendar.DATE, 1);
        sextoDia=formateador.format(cal.getTime());
        cal.add(Calendar.DATE, 1);
        septimoDia=formateador.format(cal.getTime());
        cal.add(Calendar.DATE, 1);
        octavoDia=formateador.format(cal.getTime());
        tablaPendientes.setValueAt("Prendas Lavado", 0, 0);
        tablaPendientes.setValueAt("Valets Lavado", 1, 0);
        tablaPendientes.setValueAt("Prendas Planchado", 2, 0);
        tablaPendientes.setValueAt("Valets Planchado", 3, 0);
        
        DefaultTableModel tableModel = (DefaultTableModel) tablaPendientes.getModel();
        String dias []={"Pendientes", primerDia,segundoDia,tercerDia,
           cuartoDia,quintoDia,sextoDia,septimoDia,octavoDia};
        tableModel.setColumnIdentifiers(dias);
        cargarPendientes();
        tablaPendientes.setModel(tableModel);
    }
    
    
    private void cargarPendientes() {
        DefaultTableModel modelo=(DefaultTableModel)this.tablaPendientes.getModel();
        int cantCol=modelo.getColumnCount();
        String fechaEntrega=null;
        for(int i=1;i<cantCol;i++){
            try {
                fechaEntrega=tablaPendientes.getColumnName(i);
                int prendaLavado=this.administradorOrden.getCantPendientes(fechaEntrega,TipoServicio.Lavado_Prenda.toString());
                modelo.setValueAt(prendaLavado, 0, i);
                int valetLavado=this.administradorOrden.getCantPendientes(fechaEntrega,TipoServicio.Lavado_Valet.toString());
                modelo.setValueAt(valetLavado, 1, i);
                int prendaPlanchado=this.administradorOrden.getCantPendientes(fechaEntrega,TipoServicio.Planchado_Prenda.toString());
                modelo.setValueAt(prendaPlanchado, 2, i);
                int valetPlanchado=this.administradorOrden.getCantPendientes(fechaEntrega,TipoServicio.Planchado_Valet.toString());
                modelo.setValueAt(valetPlanchado, 3, i);
            } catch (SQLException ex) {
                Logger.getLogger(AltaOrden.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
    private void cargarServiciosSeleccionados() {
        ListIterator it = serviciosContratados.listIterator();
        DefaultTableModel modelo=(DefaultTableModel)this.tablaServicio.getModel();
        while (it.hasNext()) {
            ServicioContratado s = (ServicioContratado) it.next();
            String nombre=s.getNombre();
            Double precio=s.getPrecio();
            Integer cant=s.getCantidad();
            Double subt=precio*cant;
            Object fila[]={nombre,precio,cant,subt};
            modelo.addRow(fila);
        }

    }
    
    private void cargarFechas(){
        //DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        //Calendar cal = Calendar.getInstance();
        String diahora = this.orden.getFechaHoraPedido();
        String fecha = diahora.substring(0, 10);
        String hora = diahora.substring(11);
        txtFecha.setText(fecha);
        txtHora.setText(hora);
        //Calendar hoy = Calendar.getInstance();
        
        txtFecha.setEditable(false);
        Date ahora = new Date();
        //SimpleDateFormat formateador = new SimpleDateFormat("dd/MM/yyyy");
        formateador.format(ahora);
        this.jDateChooser1.setMinSelectableDate(ahora);
    }
    
    void iniciarComponentes(Integer codOrden) throws SQLException{
        this.setSize(760,720);
        this.setTitle("Modificar Orden");
        this.setLocationRelativeTo(null);
            try {
            this.btnListo.setVisible(false);
            this.btnEntregada.setVisible(false);
            administradorOrden = new AdministradorOrden();
            this.orden=this.administradorOrden.cargarOrden(codOrden);
            idO.setText(this.orden.getCodOrden().toString());
            idO.setEditable(false);
            txtFechaPautada.setText(orden.getFechaEntregaPactada());
            String estado=orden.getSituacionOrden();
            txtEstado.setText(estado);
            this.cargarFechas();
            if(estado.equalsIgnoreCase("PENDIENTE")){
                this.btnListo.setVisible(true);
            }
            
            if(estado.equalsIgnoreCase("LISTA")){
                this.btnEntregada.setVisible(true);
            }
            DefaultTableModel modelo=(DefaultTableModel)tablaMontos.getModel();
            Object [] filaMonto={this.orden.getMontoTotal(),this.orden.getMontoAbonado(),this.orden.getMontoAdeudado()};
            modelo.addRow(filaMonto);
            this.cargarTablaPendientes();
        } catch (SQLException ex) {
            Logger.getLogger(AltaOrden.class.getName()).log(Level.SEVERE, null, ex);
        }
    
        Integer cod=this.orden.getCodCliente();
        this.administradorClientes = new AdministradorCliente();
        this.cliente = this.administradorClientes.cargarCliente(cod) ;
        this.txtIDcliente.setText(cod.toString());
        this.txtNombre.setText(cliente.getNombre());
        this.txtApellido.setText(cliente.getApellido());
        this.txtDireccion.setText(cliente.getCalle()+" "+cliente.getNroCalle());
        this.txtTel.setText(cliente.getTelFijo());
        this.txtCel.setText(cliente.getCel());
        this.serviciosContratados=new ArrayList();
        try{
            ArrayList<ServicioContratado> lista=(ArrayList<ServicioContratado>) this.administradorOrden.mostrarTodosLosServiciosContratados(orden.getCodOrden());
            this.serviciosContratados.addAll(lista);
            ArrayList<ServicioContratado> lista2=(ArrayList<ServicioContratado>)this.administradorOrden.mostrarTodosLosServiciosEspContratados(orden.getCodOrden());
            this.serviciosContratados.addAll(lista2);
            cargarServiciosSeleccionados();
        }catch(Exception e ){
            this.tablaServicio.setVisible(false);
        }
        
        this.jSpinner2.setVisible(false);
        
        this.setVisible(true);
        //iniciarTablaMontos();
    }

    /**
     * Creates new form ModificacionOrden
     */
    public ModificacionOrden(java.awt.Frame parent, boolean modal) {
        
        super(parent, modal);
        initComponents();/*
        try {
            iniciarComponentes(codOrden);
        } catch (SQLException ex) {
            Logger.getLogger(ModificacionOrden.class.getName()).log(Level.SEVERE, null, ex);
        }*/
        
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        idO = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtFecha = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtHora = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        txtEstado = new javax.swing.JTextField();
        labelEstado = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaServicio = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        tablaMontos = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        txtIDcliente = new javax.swing.JTextField();
        labelCliente = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtApellido = new javax.swing.JTextField();
        labelNombre = new javax.swing.JLabel();
        labelApellido = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        labelDireccion = new javax.swing.JLabel();
        labelTel = new javax.swing.JLabel();
        labelCel = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        txtTel = new javax.swing.JTextField();
        txtCel = new javax.swing.JTextField();
        jSeparator3 = new javax.swing.JSeparator();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jLabel11 = new javax.swing.JLabel();
        jSpinner1 = new javax.swing.JSpinner();
        jSpinner2 = new javax.swing.JSpinner();
        jScrollPane5 = new javax.swing.JScrollPane();
        tablaPendientes = new javax.swing.JTable();
        labelFechaPautada = new javax.swing.JLabel();
        txtFechaPautada = new javax.swing.JTextField();
        btnGuardarCambios = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnListo = new javax.swing.JButton();
        btnEntregada = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel6.setText("IDOrden");

        idO.setEditable(false);
        idO.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                idOActionPerformed(evt);
            }
        });

        jLabel3.setText("Hora");

        txtFecha.setEditable(false);
        txtFecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFechaActionPerformed(evt);
            }
        });

        jLabel2.setText("Fecha");

        txtHora.setEditable(false);
        txtHora.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHoraActionPerformed(evt);
            }
        });

        txtEstado.setEditable(false);

        labelEstado.setText("Estado de la orden");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(idO, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 176, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtEstado)
                            .addComponent(labelEstado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(168, 168, 168)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtFecha, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtHora, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jSeparator1))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(9, 9, 9)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(idO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(labelEstado)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, 730, 90));

        tablaServicio.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre de Servicio", "Precio", "Cantidad", "Subtotal"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaServicio.setColumnSelectionAllowed(true);
        jScrollPane1.setViewportView(tablaServicio);
        tablaServicio.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 350, -1, 109));

        tablaMontos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "TOTAL", "SEÑA", "SALDO"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaMontos.setColumnSelectionAllowed(true);
        tablaMontos.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                tablaMontosInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        tablaMontos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tablaMontosKeyPressed(evt);
            }
        });
        jScrollPane3.setViewportView(tablaMontos);
        tablaMontos.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        getContentPane().add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 470, 237, 44));

        jLabel7.setText("Nueva Fecha:");
        jLabel7.setToolTipText("");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 580, 100, 20));

        jLabel8.setText("Entrega Desde");
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 550, 100, -1));

        txtIDcliente.setEditable(false);
        txtIDcliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIDclienteActionPerformed(evt);
            }
        });

        labelCliente.setText("IDCliente");

        txtNombre.setEditable(false);

        txtApellido.setEditable(false);
        txtApellido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtApellidoActionPerformed(evt);
            }
        });

        labelNombre.setText("Nombre");

        labelApellido.setText("Apellido");

        labelDireccion.setText("Direccion");

        labelTel.setText("Telefono");

        labelCel.setText("Celular");

        txtDireccion.setEditable(false);
        txtDireccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDireccionActionPerformed(evt);
            }
        });

        txtTel.setEditable(false);
        txtTel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTelActionPerformed(evt);
            }
        });

        txtCel.setEditable(false);
        txtCel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labelCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtIDcliente, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(50, 50, 50)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(labelNombre)
                                .addGap(18, 18, 18)
                                .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(labelApellido)
                                .addGap(18, 18, 18)
                                .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelDireccion)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(labelCel)
                                .addComponent(labelTel)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDireccion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtTel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(txtCel, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelCliente)
                    .addComponent(txtIDcliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNombre)
                    .addComponent(labelDireccion)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelApellido)
                    .addComponent(labelTel)
                    .addComponent(txtTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelCel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 108, 730, 120));
        getContentPane().add(jSeparator3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 530, 720, 10));

        jDateChooser1.setDateFormatString("dd/MM/yyyy");
        jDateChooser1.setMinSelectableDate(new java.util.Date(-62135755136000L));
        getContentPane().add(jDateChooser1, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 580, 140, -1));

        jLabel11.setText("Entrega hasta");
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 580, 90, -1));
        getContentPane().add(jSpinner1, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 550, 50, -1));

        jSpinner2.setValue(8
        );
        getContentPane().add(jSpinner2, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 580, 50, -1));

        tablaPendientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "", "", "", "", "null", "null", "null", "null", "null"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane5.setViewportView(tablaPendientes);

        getContentPane().add(jScrollPane5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 230, 720, 100));

        labelFechaPautada.setText("Fecha Pautada:");
        getContentPane().add(labelFechaPautada, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 550, 100, -1));

        txtFechaPautada.setEditable(false);
        getContentPane().add(txtFechaPautada, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 550, 101, -1));

        btnGuardarCambios.setText("Guardar Cambios");
        btnGuardarCambios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarCambiosActionPerformed(evt);
            }
        });
        getContentPane().add(btnGuardarCambios, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 640, -1, -1));

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(btnCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 640, -1, -1));

        btnListo.setText("Orden Lista");
        btnListo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnListoActionPerformed(evt);
            }
        });
        getContentPane().add(btnListo, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 640, -1, -1));

        btnEntregada.setText("Orden Entregada");
        btnEntregada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEntregadaActionPerformed(evt);
            }
        });
        getContentPane().add(btnEntregada, new org.netbeans.lib.awtextra.AbsoluteConstraints(476, 640, -1, -1));
    }// </editor-fold>//GEN-END:initComponents

    private void idOActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idOActionPerformed

    }//GEN-LAST:event_idOActionPerformed

    private void txtFechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFechaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtFechaActionPerformed

    private void txtHoraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHoraActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHoraActionPerformed

    private void tablaMontosInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_tablaMontosInputMethodTextChanged

    }//GEN-LAST:event_tablaMontosInputMethodTextChanged

    private void tablaMontosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablaMontosKeyPressed

    }//GEN-LAST:event_tablaMontosKeyPressed

    private void txtIDclienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIDclienteActionPerformed

    }//GEN-LAST:event_txtIDclienteActionPerformed

    private void txtApellidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtApellidoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtApellidoActionPerformed

    private void txtTelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTelActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTelActionPerformed

    private void txtCelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCelActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCelActionPerformed

    private void txtDireccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDireccionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDireccionActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnListoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnListoActionPerformed
        String almacenaje=JOptionPane.showInputDialog(null,"Ingrese una descripción del lugar donde se almacenará el pedido","",JOptionPane.PLAIN_MESSAGE);
        try{
            if(almacenaje!=null & !almacenaje.isEmpty()){
                this.orden.ordenLista(almacenaje);
                this.txtEstado.setText(this.orden.getSituacionOrden());
                this.btnEntregada.setVisible(true);
                this.btnListo.setVisible(false);
            }
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null,"Hubo un fallo al guardar el lugar de almacenado del pedido.");
        }        
    }//GEN-LAST:event_btnListoActionPerformed

    private void btnGuardarCambiosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarCambiosActionPerformed
        if(orden.getSituacionOrden().equalsIgnoreCase("LISTA") | orden.getSituacionOrden().equalsIgnoreCase("PENDIENTE")){
            Date fecha = this.jDateChooser1.getDate();
            try {
                calendario.setTime(fecha);
            }catch (Exception e){}
            String fechaNueva = formateador.format(calendario.getTime());
            try {
                this.administradorOrden.setFechaEntregaPautada(fechaNueva, orden.getCodOrden());
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null,"Hubo un fallo al guardar la nueva fecha");
            }
        }
        try {
            String almacenaje;
            if(orden.getSituacionOrden().equalsIgnoreCase("LISTA")){
                if(this.orden.getLugarDeAlmacenajePedidoListo()!=null & !this.orden.getLugarDeAlmacenajePedidoListo().isEmpty()){
                    almacenaje =orden.getLugarDeAlmacenajePedidoListo();
                    this.administradorOrden.setLugarAlmacenaje(almacenaje,orden.getCodOrden());
                }
            }
        } catch (SQLException ex) {    
        }
        try{
            this.administradorOrden.modificarEstado(orden.getSituacionOrden(),orden.getCodOrden());
        }catch(Exception e){}
        
        
        
        if(orden.getSituacionOrden().equalsIgnoreCase("Entregada"))
            try {
                System.out.println(orden.getFechaEntrega());
                 this.administradorOrden.setFechaEntrega(orden.getFechaEntrega(),orden.getCodOrden());
                 this.administradorOrden.modificarEstado(orden.getSituacionOrden(),orden.getCodOrden());
            } catch (SQLException ex) {
            
            }
        this.dispose();
    }//GEN-LAST:event_btnGuardarCambiosActionPerformed

    private void btnEntregadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEntregadaActionPerformed
        this.orden.ordenEntregada(fechaHoy);
        orden.ordenEntregada(fechaHoy);
        this.txtEstado.setText(orden.getSituacionOrden());
    }//GEN-LAST:event_btnEntregadaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEntregada;
    private javax.swing.JButton btnGuardarCambios;
    private javax.swing.JButton btnListo;
    private javax.swing.JTextField idO;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JSpinner jSpinner2;
    private javax.swing.JLabel labelApellido;
    private javax.swing.JLabel labelCel;
    private javax.swing.JLabel labelCliente;
    private javax.swing.JLabel labelDireccion;
    private javax.swing.JLabel labelEstado;
    private javax.swing.JLabel labelFechaPautada;
    private javax.swing.JLabel labelNombre;
    private javax.swing.JLabel labelTel;
    private javax.swing.JTable tablaMontos;
    private javax.swing.JTable tablaPendientes;
    private javax.swing.JTable tablaServicio;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCel;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtEstado;
    private javax.swing.JTextField txtFecha;
    private javax.swing.JTextField txtFechaPautada;
    private javax.swing.JTextField txtHora;
    private javax.swing.JTextField txtIDcliente;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtTel;
    // End of variables declaration//GEN-END:variables
    public static void main (String args[]){
        AdministradorOrden adm;
        try {
            adm = new AdministradorOrden();
            Orden orden =adm.cargarOrden(5);
        //ModificacionOrden modOrden=new ModificacionOrden(null,true);
        } catch (SQLException ex) {
            Logger.getLogger(ModificacionOrden.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
}

